﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BookDemo.S09.S904
{
    public class S904 : IBookDemo
    {
        public void Main(string[] args)
        {
            var logger = new ServiceCollection().AddLogging(builder => builder
                   .SetMinimumLevel(LogLevel.Trace)
                   .AddConsole())
               .BuildServiceProvider()
               .GetRequiredService<ILoggerFactory>()
               .CreateLogger<Program>();

            var levels = (LogLevel[])Enum.GetValues(typeof(LogLevel));
            levels = levels.Where(it => it != LogLevel.None).ToArray();
            var eventId = 1;
            Array.ForEach(levels, level => logger.Log(level, eventId++, "This is a/an {level} log message.", level));
        }
    }
}
